#include <vector>
using namespace std;
class Solution
{
public:
    vector<int> missingTwo(vector<int> &nums)
    {
        vector<int> ans;
        ans.resize(2);
        int tmp = 0, n = nums.size();
        for (int i = 1; i <= n + 2; ++i)
        {
            tmp ^= i;
            if (i <= n)
                tmp ^= nums[i - 1];
        }
        int pos = -1;
        // 找到两个消失数的不同位
        while ((tmp >> (++pos) & 1) == 0)
            ;
        for (int i = 1; i <= n + 2; ++i)
        {
            if (i >> pos & 1)
                ans[0] ^= i;
            else
                ans[1] ^= i;
            if (i <= n)
                if (nums[i - 1] >> pos & 1)
                    ans[0] ^= nums[i - 1];
                else
                    ans[1] ^= nums[i - 1];
        }
        return ans;
    }
};